$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/agentshoppos/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'ID', width: 50, key: true },
			{ label: '商户编码', name: 'posSn', index: 'POS_SN', width: 80 }, 			
			{ label: '商户名称', name: 'posName', index: 'POS_NAME', width: 80 }, 			
			{ label: '商户管理员', name: 'posAdmin', index: 'POS_ADMIN', width: 80 }, 			
			{ label: '所属业务员', name: 'posBus', index: 'POS_BUS', width: 80 }, 			
			{ label: '业务员佣金百分比', name: 'posBusRatio', index: 'POS_BUS_RATIO', width: 80 }, 			
			{ label: '商铺佣金百分比', name: 'posRatio', index: 'POS_RATIO', width: 80 }, 			
			{ label: '商铺LOGO', name: 'posLogo', index: 'POS_LOGO', width: 80 }, 			
			{ label: '商铺图片', name: 'posImg', index: 'POS_IMG', width: 80 }, 			
			{ label: '省', name: 'province', index: 'PROVINCE', width: 80 }, 			
			{ label: '市', name: 'city', index: 'CITY', width: 80 }, 			
			{ label: '区', name: 'district', index: 'DISTRICT', width: 80 }, 			
			{ label: '详细地址', name: 'address', index: 'ADDRESS', width: 80 }, 			
			{ label: '经度', name: 'warp', index: 'WARP', width: 80 }, 			
			{ label: '纬度', name: 'weft', index: 'WEFT', width: 80 }, 			
			{ label: '计费方式', name: 'chargingType', index: 'CHARGING_TYPE', width: 80 }, 			
			{ label: '计费单位', name: 'chargingCompany', index: 'CHARGING_COMPANY', width: 80 }, 			
			{ label: '计费标准', name: 'chargingStandard', index: 'CHARGING_STANDARD', width: 80 }, 			
			{ label: '免费时长', name: 'freeTime', index: 'FREE_TIME', width: 80 }, 			
			{ label: '每日最高消费', name: 'consume', index: 'CONSUME', width: 80 }, 			
			{ label: '密码线', name: 'cipherLine', index: 'CIPHER_LINE', width: 80 }, 			
			{ label: '店铺电话', name: 'shopPhone', index: 'SHOP_PHONE', width: 80 }, 			
			{ label: '营业时间开始', name: 'startTime', index: 'START_TIME', width: 80 }, 			
			{ label: '营业时间结束', name: 'endTime', index: 'END_TIME', width: 80 }, 			
			{ label: '人均消费', name: 'money', index: 'MONEY', width: 80 }, 			
			{ label: '所属系统', name: 'sysSystem', index: 'SYS_SYSTEM', width: 80 }, 			
			{ label: '排序', name: 'sort', index: 'SORT', width: 80 }, 			
			{ label: '状态', name: 'status', index: 'STATUS', width: 80 }, 			
			{ label: '备注', name: 'remarks', index: 'REMARKS', width: 80 }, 			
			{ label: '创建时间', name: 'createdTime', index: 'CREATED_TIME', width: 80 }, 			
			{ label: '创建人员', name: 'createdUserId', index: 'CREATED_USER_ID', width: 80 }, 			
			{ label: '修改时间', name: 'modifyTime', index: 'MODIFY_TIME', width: 80 }, 			
			{ label: '修改人员', name: 'modifyUserId', index: 'MODIFY_USER_ID', width: 80 }, 			
			{ label: '版本号', name: 'version', index: 'VERSION', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		agentShopPos: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.agentShopPos = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.agentShopPos.id == null ? "sys/agentshoppos/save" : "sys/agentshoppos/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.agentShopPos),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "sys/agentshoppos/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
		getInfo: function(id){
			$.get(baseURL + "sys/agentshoppos/info/"+id, function(r){
                vm.agentShopPos = r.agentShopPos;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});